<?php
define("__ROOT_URL", strstr($_SERVER['PHP_SELF'], 'public', true));

require_once("../libs/Dispatcher.php");
require_once("../libs/coreController.php");

spl_autoload_register(NULL, FALSE);
spl_autoload_extensions('.php');
spl_autoload_register(array('Autoloader', 'load'));

class ClassNotFoundException extends Exception{}

class Autoloader
{
	public static function load($class)
	{
		if (class_exists($class, FALSE))
		{
			return;
		}

		$file = '../controllers/' . $class . '.php';
		
		if (!file_exists($file))
		{
			eval('class ' . $class . '{}');
			throw new Exception('File ' . $file . ' not found.');
			$file = '../controllers/errorController.php';
		}

		require_once($file);
		unset($file);

		if (!class_exists($class, FALSE))
		{
			eval('class ' . $class . '{}');
			throw new ClassNotFoundException('Class ' . $class . ' not found.');
			$file = '../controllers/errorController.php';
		}
	}
}

try{
	$temp = Dispatcher::dispatch();
  var_dump($temp);
}
catch (ClassNotFoundException $e){
	$error = new errorController;
	$error->index();
	//echo $e->getMessage();
	exit();
}
catch (Exception $e){
	$error = new errorController;
	$error->index();
	//echo $e->getMessage();
	exit();
}


?>